package com.qf.commerce.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.commerce.common.dto.SampleDto;
import com.qf.commerce.common.vo.SampleVo;
import com.qf.commerce.entity.Sample;
import com.qf.commerce.mapper.SampleMapper;
import com.qf.commerce.service.SampleService;
import com.qf.commerce.utils.CommonBeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Administrator
 */
@Service
public class SampleServiceImpl implements SampleService {
    @Resource
    SampleMapper sampleMapper;

    @Override
    public int addSample(SampleDto sampleDto) {
        Sample sample = CommonBeanUtils.copyForBean(sampleDto, Sample::new);
        return sampleMapper.insertSample(sample);
    }

    @Override
    public int deleteSampleById(Long sampleId) {
        return sampleMapper.deleteSample(sampleId);
    }

    @Override
    public int deleteSampleByIds(List<Long> sampleIds) {
        return sampleMapper.deleteSamples(sampleIds);
    }

    @Override
    public int modifySampleById(SampleDto sampleDto) {
        Sample sample = CommonBeanUtils.copyForBean(sampleDto, Sample::new);
        return sampleMapper.updateSample(sample);
    }

    @Override
    public PageInfo<SampleVo> querySampleList(Integer currentPage) {
        return CommonBeanUtils.copyPage(PageHelper.startPage(currentPage,10).
                        doSelectPageInfo(()->sampleMapper.selectSampleList())
                ,new PageInfo<SampleVo>(),SampleVo::new);
    }

    @Override
    public PageInfo<SampleVo> querySampleByName(String modelName,Integer currentPage) {
        return CommonBeanUtils.copyPage(PageHelper.startPage(currentPage,10).doSelectPageInfo(()->sampleMapper.selectSampleListByName(modelName)),
                new PageInfo<SampleVo>(),SampleVo::new);
    }
}
